{extend name="public/edit" /}

{block name="content"}
    <div class="layui-form-item">
        <label class="layui-form-label">内容类型</label>
        <input type="radio" lay-filter="type" name="type" value="1" title="图片" checked>
        <input type="radio" lay-filter="type" name="type" value="2" title="内容" >    
    </div>
    <div class="layui-form-item img">
        <label class="layui-form-label">轮播图片</label>
        <div class="layui-input-block">
            <div class="layui-upload">
                <button type="button" name="img" number="1" class="layui-btn form-file-pic">选择文件</button>
                <div class="layui-upload-list">

                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-form-text content" style="display: none">
        <label class="layui-form-label">文章内容</label>
        <div class="layui-input-block">
            {:get_um('content')}
        </div>
    </div>
    <div class="layui-form-item layui-form-text" >
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="text" name="sort" value="" lay-verify="required|number" placeholder="点此请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否设置为背景</label>
        <div class="layui-input-block">
            <input type="radio" name="is_back"  lay-verify="required"  autocomplete="off"  value="1" title="是"  
                class="layui-input">
            <input type="radio" name="is_back" lay-verify="required"  autocomplete="off" title="否" value="0" checked
                class="layui-input">   
        </div>
    </div>  
    <div class="layui-form-item">
        <label class="layui-form-label">是否显示</label>
        <div class="layui-input-block">
            <input type="radio" name="slide_show"  lay-verify="required"  autocomplete="off"  value="1" title="是"  checked
                class="layui-input">
            <input type="radio" name="slide_show" lay-verify="required"  autocomplete="off" title="否" value="0"
                class="layui-input">   
        </div>
    </div>

{/block}

{block name="script"}
<script>
   
   views.verify(false).func(function(form,admin,upload,laydate){
        upload.render({
            elem: '#test-upload-normal'
            ,url: '/api/upload/'
            ,auto: false //选择文件后不自动上传
            ,bindAction: '' //指向一个按钮触发上传
            ,size:'1024'
            ,choose: function(obj){
                //将每次选择的文件追加到文件队列
                var files = obj.pushFile();
                
                //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
                obj.preview(function(index, file, result){
                    // console.log(index); //得到文件索引
                    layui.$('#test-upload-normal-s').attr('src',result);
                    layui.$('input[name="pic"]').val(result)
                    layui.$('input[name="agency_life_shop_pic"]').val(file.name)
                });
            }
        });      
    }).get();

    layui.use(['form','laydate'], function(){
        var laydate = layui.laydate;
        var form = layui.form, layer = layui.layer;
        //console.log(form);
        form.on('radio(type)', function (data) {
            var type = data.value;
            if(type==1){
                console.log($('.img'));
                layui.$('.img').css('display','block');
                layui.$('.content').css('display','none');
                form.render();
            }
            if(type==2){
                layui.$('.content').css('display','block');
                layui.$('.img').css('display','none');
                form.render();
            }
        });

    })
</script>
{/block}